<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: ActiveScaffold::Finder</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">ActiveScaffold::Finder</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/plugins/active_scaffold/lib/finder_rb.html">
                vendor/plugins/active_scaffold/lib/finder.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000269">active_scaffold_conditions</a>&nbsp;&nbsp;
      <a href="#M000270">active_scaffold_joins</a>&nbsp;&nbsp;
      <a href="#M000271">all_conditions</a>&nbsp;&nbsp;
      <a href="#M000275">build_order_clause</a>&nbsp;&nbsp;
      <a href="#M000268">condition_for_column</a>&nbsp;&nbsp;
      <a href="#M000267">create_conditions_for_columns</a>&nbsp;&nbsp;
      <a href="#M000272">find_if_allowed</a>&nbsp;&nbsp;
      <a href="#M000273">find_page</a>&nbsp;&nbsp;
      <a href="#M000274">merge_conditions</a>&nbsp;&nbsp;
      <a href="#M000276">sort_collection_by_column</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">active_scaffold_conditions</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">active_scaffold_joins</td>
          <td class="context-item-value">&nbsp;[W]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000268" class="method-detail">
        <a name="M000268"></a>

        <div class="method-heading">
          <a href="#M000268" class="method-signature">
          <span class="method-name">condition_for_column</span><span class="method-args">(column, value, like_pattern = '%?%')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Generates an SQL condition for the given <a
href="../ActiveScaffold.html">ActiveScaffold</a> column based on that
column&#8216;s database type (or form_ui &#8230; for virtual columns?).
TODO: this should reside on the column, not the controller
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000268-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000268-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 27</span>
27:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">condition_for_column</span>(<span class="ruby-identifier">column</span>, <span class="ruby-identifier">value</span>, <span class="ruby-identifier">like_pattern</span> = <span class="ruby-value str">'%?%'</span>)
28:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">column</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">search_sql</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">value</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">empty?</span>
29:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">form_ui</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">column</span>.<span class="ruby-identifier">column</span>.<span class="ruby-identifier">type</span>
30:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:boolean</span>, <span class="ruby-identifier">:checkbox</span>
31:         [<span class="ruby-node">&quot;#{column.search_sql} = ?&quot;</span>, (<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>)]
32: 
33:         <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:integer</span>
34:         [<span class="ruby-node">&quot;#{column.search_sql} = ?&quot;</span>, <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_i</span>]
35: 
36:         <span class="ruby-keyword kw">else</span>
37:         [<span class="ruby-node">&quot;LOWER(#{column.search_sql}) LIKE ?&quot;</span>, <span class="ruby-identifier">like_pattern</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">'?'</span>, <span class="ruby-identifier">value</span>.<span class="ruby-identifier">downcase</span>)]
38:       <span class="ruby-keyword kw">end</span>
39:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000267" class="method-detail">
        <a name="M000267"></a>

        <div class="method-heading">
          <a href="#M000267" class="method-signature">
          <span class="method-name">create_conditions_for_columns</span><span class="method-args">(tokens, columns, like_pattern = '%?%')</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Takes a collection of search terms (the tokens) and creates SQL that
searches all specified <a href="../ActiveScaffold.html">ActiveScaffold</a>
columns. A row will match if each token is found in at least one of the
columns.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000267-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000267-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 6</span>
 6:     <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">create_conditions_for_columns</span>(<span class="ruby-identifier">tokens</span>, <span class="ruby-identifier">columns</span>, <span class="ruby-identifier">like_pattern</span> = <span class="ruby-value str">'%?%'</span>)
 7:       <span class="ruby-comment cmt"># if there aren't any columns, then just return a nil condition</span>
 8:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
 9: 
10:       <span class="ruby-identifier">tokens</span> = [<span class="ruby-identifier">tokens</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">tokens</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">String</span>
11: 
12:       <span class="ruby-identifier">where_clauses</span> = []
13:       <span class="ruby-identifier">columns</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">column</span><span class="ruby-operator">|</span>
14:         <span class="ruby-identifier">where_clauses</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;LOWER(#{column.search_sql}) LIKE ?&quot;</span>
15:       <span class="ruby-keyword kw">end</span>
16:       <span class="ruby-identifier">phrase</span> = <span class="ruby-node">&quot;(#{where_clauses.join(' OR ')})&quot;</span>
17: 
18:       <span class="ruby-identifier">sql</span> = ([<span class="ruby-identifier">phrase</span>] <span class="ruby-operator">*</span> <span class="ruby-identifier">tokens</span>.<span class="ruby-identifier">length</span>).<span class="ruby-identifier">join</span>(<span class="ruby-value str">' AND '</span>)
19:       <span class="ruby-identifier">tokens</span> = <span class="ruby-identifier">tokens</span>.<span class="ruby-identifier">collect</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">like_pattern</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-value str">'?'</span>, <span class="ruby-identifier">value</span>.<span class="ruby-identifier">downcase</span>)] <span class="ruby-operator">*</span> <span class="ruby-identifier">where_clauses</span>.<span class="ruby-identifier">length</span> }.<span class="ruby-identifier">flatten</span>
20: 
21:       [<span class="ruby-identifier">sql</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">tokens</span>]
22:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Protected Instance methods</h3>

      <div id="method-M000269" class="method-detail">
        <a name="M000269"></a>

        <div class="method-heading">
          <a href="#M000269" class="method-signature">
          <span class="method-name">active_scaffold_conditions</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000269-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000269-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 44</span>
44:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_scaffold_conditions</span>
45:       <span class="ruby-ivar">@active_scaffold_conditions</span> <span class="ruby-operator">||=</span> []
46:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000270" class="method-detail">
        <a name="M000270"></a>

        <div class="method-heading">
          <a href="#M000270" class="method-signature">
          <span class="method-name">active_scaffold_joins</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000270-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000270-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 49</span>
49:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">active_scaffold_joins</span>
50:       <span class="ruby-ivar">@active_scaffold_joins</span> <span class="ruby-operator">||=</span> []
51:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000271" class="method-detail">
        <a name="M000271"></a>

        <div class="method-heading">
          <a href="#M000271" class="method-signature">
          <span class="method-name">all_conditions</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000271-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000271-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 53</span>
53:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">all_conditions</span>
54:       <span class="ruby-identifier">merge_conditions</span>(
55:         <span class="ruby-identifier">active_scaffold_conditions</span>,                   <span class="ruby-comment cmt"># from the search modules</span>
56:         <span class="ruby-identifier">conditions_for_collection</span>,                    <span class="ruby-comment cmt"># from the dev</span>
57:         <span class="ruby-identifier">conditions_from_params</span>,                       <span class="ruby-comment cmt"># from the parameters (e.g. /users/list?first_name=Fred)</span>
58:         <span class="ruby-identifier">conditions_from_constraints</span>,                  <span class="ruby-comment cmt"># from any constraints (embedded scaffolds)</span>
59:         <span class="ruby-identifier">active_scaffold_session_storage</span>[<span class="ruby-identifier">:conditions</span>] <span class="ruby-comment cmt"># embedding conditions (weaker constraints)</span>
60:       )
61:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000275" class="method-detail">
        <a name="M000275"></a>

        <div class="method-heading">
          <a href="#M000275" class="method-signature">
          <span class="method-name">build_order_clause</span><span class="method-args">(sorting)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
accepts a DataStructure::Sorting object and builds an order-by clause TODO:
this should reside on the model, not the controller
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000275-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000275-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 118</span>
118:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">build_order_clause</span>(<span class="ruby-identifier">sorting</span>)
119:       <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sorting</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">sorting</span>.<span class="ruby-identifier">sorts_by_method?</span>
120: 
121:       <span class="ruby-comment cmt"># unless the sorting is by method, create the sql string</span>
122:       <span class="ruby-identifier">order</span> = []
123:       <span class="ruby-identifier">sorting</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">clause</span><span class="ruby-operator">|</span>
124:         <span class="ruby-identifier">sort_column</span>, <span class="ruby-identifier">sort_direction</span> = <span class="ruby-identifier">clause</span>
125:         <span class="ruby-identifier">sql</span> = <span class="ruby-identifier">sort_column</span>.<span class="ruby-identifier">sort</span>[<span class="ruby-identifier">:sql</span>]
126:         <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sql</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">sql</span>.<span class="ruby-identifier">empty?</span>
127: 
128:         <span class="ruby-identifier">order</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{sql} #{sort_direction}&quot;</span>
129:       <span class="ruby-keyword kw">end</span>
130: 
131:       <span class="ruby-identifier">order</span> = <span class="ruby-identifier">order</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">', '</span>)
132:       <span class="ruby-identifier">order</span> = <span class="ruby-keyword kw">nil</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">order</span>.<span class="ruby-identifier">empty?</span>
133: 
134:       <span class="ruby-identifier">order</span>
135:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000272" class="method-detail">
        <a name="M000272"></a>

        <div class="method-heading">
          <a href="#M000272" class="method-signature">
          <span class="method-name">find_if_allowed</span><span class="method-args">(id, action, klass = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
returns a single record (the given id) but only if it&#8216;s allowed for
the specified action. accomplishes this by checking
model.#{action}_authorized? TODO: this should reside on the model, not the
controller
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000272-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000272-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 66</span>
66:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_if_allowed</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">action</span>, <span class="ruby-identifier">klass</span> = <span class="ruby-keyword kw">nil</span>)
67:       <span class="ruby-identifier">klass</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>
68:       <span class="ruby-identifier">record</span> = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">id</span>)
69:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">ActiveScaffold</span><span class="ruby-operator">::</span><span class="ruby-constant">RecordNotAllowed</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">record</span>.<span class="ruby-identifier">authorized_for?</span>(<span class="ruby-identifier">:action</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">action</span>.<span class="ruby-identifier">to_sym</span>)
70:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">record</span>
71:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000273" class="method-detail">
        <a name="M000273"></a>

        <div class="method-heading">
          <a href="#M000273" class="method-signature">
          <span class="method-name">find_page</span><span class="method-args">(options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
returns a <a href="../Paginator/Page.html">Paginator::Page</a> (not from <a
href="../Paginator.html">ActiveRecord::Paginator</a>) for the given
parameters options may include:
</p>
<ul>
<li>:sorting - a Sorting DataStructure (basically an array of hashes of field
=&gt; direction, e.g. [{:field1 =&gt; &#8216;asc&#8217;}, {:field2 =&gt;
&#8216;desc&#8217;}]). please note that multi-column sorting has some
limitations: if any column in a multi-field sort uses method-based sorting,
it will be ignored. method sorting only works for single-column sorting.

</li>
<li>:per_page

</li>
<li>:page

</li>
</ul>
<p>
TODO: this should reside on the model, not the controller
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000273-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000273-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 79</span>
 79:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find_page</span>(<span class="ruby-identifier">options</span> = {})
 80:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">assert_valid_keys</span> <span class="ruby-identifier">:sorting</span>, <span class="ruby-identifier">:per_page</span>, <span class="ruby-identifier">:page</span>
 81:       <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:per_page</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">999999999</span>
 82:       <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:page</span>] <span class="ruby-operator">||=</span> <span class="ruby-value">1</span>
 83: 
 84:       <span class="ruby-identifier">klass</span> = <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>
 85: 
 86:       <span class="ruby-comment cmt"># create a general-use options array that's compatible with Rails finders</span>
 87:       <span class="ruby-identifier">finder_options</span> = { <span class="ruby-identifier">:order</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">build_order_clause</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sorting</span>]),
 88:                          <span class="ruby-identifier">:conditions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">all_conditions</span>,
 89:                          <span class="ruby-identifier">:joins</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">joins_for_collection</span>,
 90:                          <span class="ruby-identifier">:include</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">active_scaffold_joins</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">active_scaffold_joins</span>}
 91: 
 92:       <span class="ruby-comment cmt"># NOTE: we must use :include in the count query, because some conditions may reference other tables</span>
 93:       <span class="ruby-identifier">count</span> = <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">count</span>(<span class="ruby-identifier">finder_options</span>.<span class="ruby-identifier">reject</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span> [<span class="ruby-identifier">:order</span>].<span class="ruby-identifier">include?</span> <span class="ruby-identifier">k</span>})
 94: 
 95:       <span class="ruby-comment cmt"># we build the paginator differently for method- and sql-based sorting</span>
 96:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sorting</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sorting</span>].<span class="ruby-identifier">sorts_by_method?</span>
 97:         <span class="ruby-identifier">pager</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Paginator</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">count</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:per_page</span>]) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">offset</span>, <span class="ruby-identifier">per_page</span><span class="ruby-operator">|</span>
 98:           <span class="ruby-identifier">sorted_collection</span> = <span class="ruby-identifier">sort_collection_by_column</span>(<span class="ruby-identifier">klass</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">finder_options</span>), <span class="ruby-operator">*</span><span class="ruby-identifier">options</span>[<span class="ruby-identifier">:sorting</span>].<span class="ruby-identifier">first</span>)
 99:           <span class="ruby-identifier">sorted_collection</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-identifier">offset</span>, <span class="ruby-identifier">per_page</span>)
100:         <span class="ruby-keyword kw">end</span>
101:       <span class="ruby-keyword kw">else</span>
102:         <span class="ruby-identifier">pager</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Paginator</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">count</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:per_page</span>]) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">offset</span>, <span class="ruby-identifier">per_page</span><span class="ruby-operator">|</span>
103:           <span class="ruby-identifier">klass</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">:all</span>, <span class="ruby-identifier">finder_options</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:offset</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">offset</span>, <span class="ruby-identifier">:limit</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">per_page</span>))
104:         <span class="ruby-keyword kw">end</span>
105:       <span class="ruby-keyword kw">end</span>
106: 
107:       <span class="ruby-identifier">pager</span>.<span class="ruby-identifier">page</span>(<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:page</span>])
108:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000274" class="method-detail">
        <a name="M000274"></a>

        <div class="method-heading">
          <a href="#M000274" class="method-signature">
          <span class="method-name">merge_conditions</span><span class="method-args">(*conditions)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
TODO: this should reside on the model, not the controller
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000274-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000274-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 111</span>
111:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">merge_conditions</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">conditions</span>)
112:       <span class="ruby-identifier">c</span> = <span class="ruby-identifier">conditions</span>.<span class="ruby-identifier">find_all</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">empty?</span> }
113:       <span class="ruby-identifier">c</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">c</span>.<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span> <span class="ruby-identifier">active_scaffold_config</span>.<span class="ruby-identifier">model</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:sanitize_sql</span>, <span class="ruby-identifier">c</span>)}.<span class="ruby-identifier">join</span>(<span class="ruby-value str">' AND '</span>)
114:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000276" class="method-detail">
        <a name="M000276"></a>

        <div class="method-heading">
          <a href="#M000276" class="method-signature">
          <span class="method-name">sort_collection_by_column</span><span class="method-args">(collection, column, order)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
TODO: this should reside on the column, not the controller
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000276-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000276-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/plugins/active_scaffold/lib/finder.rb, line 138</span>
138:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sort_collection_by_column</span>(<span class="ruby-identifier">collection</span>, <span class="ruby-identifier">column</span>, <span class="ruby-identifier">order</span>)
139:       <span class="ruby-identifier">sorter</span> = <span class="ruby-identifier">column</span>.<span class="ruby-identifier">sort</span>[<span class="ruby-identifier">:method</span>]
140:       <span class="ruby-identifier">collection</span> = <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">sort_by</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">record</span><span class="ruby-operator">|</span>
141:         <span class="ruby-identifier">value</span> = (<span class="ruby-identifier">sorter</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Proc</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">record</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">sorter</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">record</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-identifier">sorter</span>)
142:         <span class="ruby-identifier">value</span> = <span class="ruby-value str">''</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
143:         <span class="ruby-identifier">value</span>
144:       }
145:       <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">reverse!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">order</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'desc'</span>
146:       <span class="ruby-identifier">collection</span>
147:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>